<template>
    <div>
        <h1>活动管理</h1>
        <div>
            活动标题:
            <input type="text" v-model="info.testname">
            分类:
           <select v-model="info.typeid">
                            <option value="">请选择</option>
                            <option v-for="item in tests" :value="item.typeId">{{ item.typeName }}</option>
           </select> 
           <input type="button" value="查询" @click="showuser" class="btn btn-primary">
        </div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>活动标题</td>
                    <td>分类</td>
                    <td>图片</td>
                    <td>活动日期</td>
                    <td>活动地点</td>
                    <td>报名截止日期</td>
                    <td>活动详情</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in list" :key="item.id" >
                    <td>{{item.testName}}</td>
                    <td>{{item.typeName}}</td>
                    <td><img :src=" item.testPhoto " width="60" height="60"></td>
                    <td>{{moment(item.startTime).format('YYYY-MM-DD')}}</td>
                    <td>{{item.address}}</td>
                    <td>{{moment(item.endTime).format('YYYY-MM-DD')}}</td>
                    <td>{{item.testDesc}}</td>
                    <td><input type="button" value="编辑" @click="updtest(item.id)" class="btn btn-success"></td>
                </tr>
            </tbody>
        </table>
       
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from "vue";
import axios from "axios";
import moment from "moment";
import {useRouter,useRoute} from "vue-router";
const router=useRouter();
const route=useRoute();
onMounted(()=>
{
    bindtest();
    showuser();
})
let info:any=reactive({
  
  "testname": "",
  "typeid": ""
   
})
let list:any=ref([]);
const showuser=()=>
{
    
    axios({
        url:'http://localhost:5086/api/User/ShowTest',
        method:'get',
        params:info
    })
    .then((res)=>
    {
        console.log(res);
        list.value=res.data;
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
let tests:any=ref([]);
const bindtest=()=>
{
    axios({
        url:'http://localhost:5086/api/User/BindType',
        method:'get',
    })
    .then((res)=>
    {
        console.log(res);
        tests.value=res.data;
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
const updtest=(id:any)=>
{
    router.push({
        path:'/updatetest',
        query:{
            id:id
        }
    })
}


</script>

<style scoped>

</style>